home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 26 (Anniversary Edition)
/
Volume 26 [Anniversary Edition] - JOGO DISK .iso
/
DEPOSITO
/
REmovido
/
Esportes
/
LightningBreak.swf
/
scripts
/
frame_1
/
DoAction_9.as
< prev
next >
Wrap
Text File
|
2006-06-13
|
23KB
|
861 lines
submitScore = function()
{
game = "lightningbreak";
score = _root.totalScore;
if(_url.indexOf("playaholics") != -1)
{
getURL("http://www.playaholics.com/comp_entry.php","_top","POST");
}
else if(_url.indexOf("bluesqgames") != -1)
{
_root.submit.loadVariables("http://www.bluesqgames.net/multigame/submitscore/index.php?game_name=" + game + "&score=" + score,_root.submit);
getUrl("http://www.bluesqgames.net/multigame/playagain/index.php", "_top");
}
};
cleanup = function()
{
Mouse.removeListener(this.stepAim);
Mouse.removeListener(this.stepPower);
this.onMouseDown = 0;
this.onMouseUp = 0;
this.onEnterFrame = 0;
this.timer.running = false;
_root.snd.stopAll();
_root.endGame();
};
endGame = function()
{
if(_root.gameEnded)
{
return undefined;
}
_root.gameEnded = true;
if(_root.totalScore > 0)
{
_root.user.data.tr = int(_root.user.data.tr) + 1;
if(_root.user.data.tr == 0)
{
_root.user.data.tr = 1;
}
_root.user.data.th = Math.max(_root.totalScore,int(_root.user.data.th));
_root.user.data.ta = (Number(_root.user.data.ta) * (_root.user.data.tr - 1) + _root.totalScore) / _root.user.data.tr;
_root.flush();
}
};
this.timer = createEmptyMovieClip("timer",99);
this.timer.running = false;
this.timer.speed = 1;
timer.init = function(timeTotal)
{
this.timeTotal = timeTotal * 1000;
this.timeStart = getTimer();
_root.timeLeft = this.timeTotal;
this.running = false;
};
timer.onEnterFrame = function()
{
if(_root.paused)
{
this.timestamp = getTimer();
return undefined;
}
_global.dt = (getTimer() - this.timestamp) / 33 * 0.3 + _global.dt * 0.7;
this.timestamp = getTimer();
if(this.running)
{
_root.timeLeft -= _global.dt * 33 * this.speed;
}
this.update();
};
timer.update = function()
{
if(_root.paused)
{
return undefined;
}
_root.bg.time.time.time.gotoAndStop(Math.max(Math.floor(_root.timeLeft / 1000) + 2,1));
if(_root.timeLeft <= -0.5 && this.running)
{
this.running = false;
if(_root.onEnterFrame != stepRoll)
{
_root.startLevelOver();
}
}
};
timer.initColorSwap = function()
{
this.colorSwapTimer = 0;
var i = 1;
while(i < _root.ballsAmount)
{
_root.balls[i].initColorSwap();
i++;
}
};
timer.stepColorSwap = function()
{
if(_root.paused)
{
return undefined;
}
if(!_root.lvl.colorSwap)
{
return undefined;
}
this.colorSwapTimer += _global.dt;
if(this.colorSwapTimer > _root.swapTimerThreashold)
{
this.colorSwapTimer = 0;
_root.colorSwap();
}
};
timer.timestamp = getTimer();
initGame = function()
{
_root.levelsPlayed = 0;
_root.totalShots = 0;
_root.gameEnded = false;
_root.actScore = 0;
_root.totalScore = 0;
_root.actBreak = 0;
_root.timeLeft = -1;
_root.pointer.gotoAndStop("wait");
_root.timer.running = false;
initTable();
loadLevel(_root.actLvl);
};
initTable = function()
{
this.balls = new Array();
var i = 0;
while(i < this.ballsAmount + 1)
{
this.balls[i] = new CBall(i,this["b" + i]);
i++;
}
this.lids = new Array();
var i = 0;
while(i < 6)
{
this.lids[i] = _root["l" + i];
i++;
}
};
loadLevel = function(id)
{
_root.actLvl = id;
_root.actLevel = _root.actLvl + 1;
if(_root.actLvl > _root.maxLevel)
{
_root.user.data.maxLevel = _root.actLvl;
_root.flush();
_root.maxLevel = int(_root.user.data.maxLevel);
}
_root.actScore = 0;
_root.actBreak = 0;
_root.actPottedRed = 0;
_root.actPottedColor = 0;
_root.actPottedOrder = "";
_root.nominatedNext = 1;
_root.actRoundsPlayed = _root.stats[this.actLvl].rounds;
_root.actHighScore = _root.stats[this.actLvl].highscore;
_root.actAvgScore = _root.stats[this.actLvl].average;
_root.lvl = _root.lvls[_root.actLvl % 20];
_root.lvl.init();
_root.timePerLevel = this.lvl.time * (1 - Math.floor(_root.actLvl / 20) * 0.1) + 0.99;
if(_root.timePerLevel == 100.99)
{
_root.timePerLevel = 99.99;
}
_root.bg.outer.gotoAndStop(_root.lvl.skin);
_root.bg.time.inner.gotoAndStop(_root.lvl.skin);
if(_root.lvl.breakout)
{
_root.balls[8].setPos(100,100);
_root.balls[8].reset();
}
_root.h0._visible = _root.lvl.frame != 1;
_root.h1._visible = _root.lvl.frame != 1;
_root.h2._visible = _root.lvl.frame != 1;
_root.h3._visible = _root.lvl.frame != 2;
_root.h4._visible = _root.lvl.frame != 2;
_root.h5._visible = _root.lvl.frame != 2;
_root.frame.gotoAndStop(_root.lvl.frame + 1);
_root.table = _root.tables[_root.lvl.frame];
_root.startLevel();
};
startLevel = function()
{
this.phase = 0;
this.onEnterFrame = this.stepLevel;
this.nominated = 1;
_root.timer.initColorSwap();
};
stepLevel = function()
{
if(this.paused)
{
return undefined;
}
this.timer.stepColorSwap();
if(this.phaseDelay > 0)
{
this.phaseDelay -= _global.dt;
return undefined;
}
switch(this.phase)
{
case 0:
_root.snd.play("levelmusic");
_root.bg.gotoAndPlay("level");
this.phase = this.phase + 1;
break;
case 1:
break;
case 2:
_root.osd.gotoAndPlay("level");
this.phase = this.phase + 1;
break;
case 3:
break;
case 4:
_root.osd.gotoAndPlay("countdown3");
_root.snd.playEvent("tic",50);
this.phaseDelay = 20;
this.phase = this.phase + 1;
break;
case 5:
_root.osd.gotoAndPlay("countdown2");
_root.snd.playEvent("tic",50);
this.phaseDelay = 20;
this.phase = this.phase + 1;
break;
case 6:
_root.osd.gotoAndPlay("countdown1");
_root.snd.playEvent("tic",50);
this.phaseDelay = 20;
this.phase = this.phase + 1;
break;
case 7:
_root.osd.gotoAndPlay("go");
_root.snd.play("go");
this.phaseDelay = 20;
this.phase = this.phase + 1;
case 8:
if(this.totalShots > 0 || this.actLvl != 0)
{
_root.spotBall(0);
_root.spotBall(1,1);
}
var i = 0;
while(i < _root.ballsAmount + _root.lvl.breakout)
{
_root.balls[i].mc.gotoAndPlay("appear");
i++;
}
this.phaseDelay = 10;
this.phase = this.phase + 1;
break;
case 9:
_root.timer.running = true;
startAim();
}
};
startAim = function()
{
this.nominated = this.nominatedNext;
this.validPotMode = 0;
this.shotPots = "";
_root.pointer.gotoAndStop("aim");
var i = 0;
while(i < _root.ballsAmount)
{
if(_root.balls[i].spot || int(_root.balls[i].x) == 0 || int(_root.balls[i].y) == 0)
{
_root.spotBall(i);
}
i++;
}
_root.cue._visible = true;
_root.cue.scale._visible = false;
_root.cue.gfx._y = this.balls[0].radius * -1 - this.aimDistance;
_root.cue._x = this.balls[0].x;
_root.cue._y = this.balls[0].y;
if(_root.lvl.needOrder eq "")
{
if(this.nominated > 0)
{
this.balls[this.nominated].mc.marker.gotoAndPlay("active");
}
else
{
var i = 2;
while(i < _root.ballsAmount)
{
this.balls[i].mc.marker.gotoAndPlay("active");
i++;
}
}
}
else
{
var target = _root.lvl.needOrder.charAt(_root.actPottedOrder.length);
this.balls[target].mc.marker.gotoAndPlay("active");
this.nominated = target;
}
var i = 0;
while(i < this.ballsAmount)
{
this.balls[i].showLabel();
i++;
}
Mouse.addListener(this.stepAim);
this.onEnterFrame = this.stepAim;
};
stepAim = function()
{
if(_root.paused)
{
return undefined;
}
this.timer.stepColorSwap();
if(this.phaseDelay > 0)
{
this.phaseDelay -= _global.dt;
return undefined;
}
if(_root._ymouse > 348)
{
_root.pointer.gotoAndStop("wait");
}
else
{
_root.pointer.gotoAndStop("aim");
}
_root.cue._alpha = Math.min(_root.cue._alpha + 15,100);
_root.cue._rotation = _global.v2d.math.r2vertSgnAngle(this.balls[0].x,this.balls[0].y,_root._xmouse,_root._ymouse) / 3.141592653589793 * 180 - 180;
_root.aimVector = _global.v2d.math.unify({x:_root._xmouse - _root.balls[0].x,y:_root._ymouse - _root.balls[0].y});
};
stepAim.onMouseDown = function()
{
if(_root.paused)
{
return undefined;
}
if(_root._ymouse > 348)
{
return undefined;
}
Mouse.removeListener(this);
_root.startPower();
};
startPower = function()
{
Mouse.addListener(this.stepPower);
_root.cue._alpha = 100;
_root.cue.scale._visible = true;
_root.cue.scale._y = this.balls[0].radius * -1 - this.aimDistance;
this.startPowerTime = getTimer();
this.powerOld = 0;
this.powerAct = 0;
this.powerV = 0;
this.onEnterFrame = this.stepPower;
};
stepPower = function()
{
if(_root.paused)
{
return undefined;
}
this.stepAim();
var dt = getTimer() - this.startPowerTime;
this.powerAct = (1 - Math.cos(dt / 350)) / 2;
this.cueV = (this.powerAct - this.powerOld) * this.aimRange * -1 / _global.dt;
this.cue.scale.gotoAndStop(1 + Math.floor(this.powerAct * 50));
this.pointer.gotoAndStop(2 + Math.floor(this.powerAct * 50));
this.powerOld = this.powerAct;
_root.cue.gfx._y = this.balls[0].radius * -1 - this.aimDistance - this.powerAct * this.aimRange;
};
stepPower.onMouseUp = function()
{
Mouse.removeListener(this);
_root.pointer.gotoAndStop(1);
_root.cue.scale._visible = false;
_root.cueA = Math.max(Math.pow(_root.powerAct * 4,1.8),0.1);
_root.startShoot();
};
startShoot = function()
{
this.totalShots = this.totalShots + 1;
this.onEnterFrame = this.stepShoot;
var i = 0;
while(i < this.ballsAmount)
{
this.balls[i].hideLabel();
i++;
}
};
stepShoot = function()
{
if(_root.paused)
{
return undefined;
}
this.timer.stepColorSwap();
ty = _root.cue.gfx._y + this.cueV * _global.dt;
this.cueV += this.cueA * _global.dt;
if(ty > this.balls[0].radius * -1)
{
ty = this.balls[0].radius * -1;
_root.snd.playEvent("cuehit",_root.powerAct);
this.cueV *= _root.lvl.speedUp;
this.balls[0].vx = this.aimVector.x * this.cueV;
this.balls[0].vy = this.aimVector.y * this.cueV;
this.startRoll();
}
_root.cue.gfx._y = ty;
};
startRoll = function()
{
var i = 1;
while(i < _root.ballsAmount)
{
if(this.balls[i].mc.marker._currentframe > 1)
{
this.balls[i].mc.marker.gotoAndPlay("vanish");
}
i++;
}
this.replaySave();
_root.pointer.gotoAndStop("wait");
this.firstHit = 0;
this.stepRollCount = 0;
this.onEnterFrame = this.stepRoll;
};
stepRoll = function()
{
if(_root.paused)
{
return undefined;
}
this.timer.stepColorSwap();
if(this.steps == 0)
{
return undefined;
}
if(this.steps > 0)
{
this.steps--;
}
_root.gstep.clear();
this.stepRollTotalMovement = 0;
var i = 0;
while(i < this.ballsAmount + _root.lvl.breakout)
{
this.balls[i].move();
i++;
}
this.stepRollCount += _global.dt;
if(this.stepRollCount > 30)
{
if(_root.cue._alpha > 0)
{
_root.cue._alpha = Math.max(_root.cue._alpha * 0.8 - 1,0);
}
else
{
_root.cue._visible = false;
}
if(this.stepRollTotalMovement < 0.2)
{
var i = 0;
while(i < this.ballsAmount)
{
this.balls[i].setSpeed(0,0);
i++;
}
_root.pointer.gotoAndStop("ready");
if(_root.missionAccomplished())
{
this.startLevelOver();
return undefined;
}
var allPotted = true;
var i = 1;
while(i < _root.ballsAmount)
{
if(_root.balls[i].potted == -1)
{
allPotted = false;
}
i++;
}
if(allPotted)
{
this.startLevelOver();
return undefined;
}
if(_root.firstHit == 0 && _root.balls[0].potted == -1)
{
_root.foul(4,"- 4 seconds for missing");
}
if(_root.lvl.needExact != 0 && _root.lvl.actBreak > _root.lvl.needExact)
{
this.startLevelOver();
return undefined;
}
if(this.timeLeft <= 0)
{
this.startLevelOver();
}
else
{
this.startAim();
}
}
}
};
startLevelOver = function(gameover)
{
this.phase = 0;
if(gameover)
{
this.phase = "alreadydead";
}
this.phaseDelay = 0;
Mouse.removeListener(this.stepPower);
Mouse.removeListener(this.stepAim);
this.pointer.gotoAndStop("wait");
this.onEnterFrame = this.stepLevelOver;
_root.stats[this.actLvl].rounds = _root.stats[this.actLvl].rounds + 1;
_root.stats[this.actLvl].highscore = Math.max(_root.stats[this.actLvl].highscore,_root.actScore);
_root.stats[this.actLvl].average = Math.round((_root.stats[this.actLvl].average * (_root.stats[this.actLvl].rounds - 1) + _root.actScore) / _root.stats[this.actLvl].rounds);
_root.user.data[this.actLvl + "r"] = _root.stats[this.actLvl].rounds;
_root.user.data[this.actLvl + "h"] = _root.stats[this.actLvl].highscore;
_root.user.data[this.actLvl + "a"] = _root.stats[this.actLvl].average;
_root.flush();
};
stepLevelOver = function()
{
if(_root.paused)
{
return undefined;
}
if(_root.cue._alpha > 0)
{
_root.cue._alpha = Math.max(_root.cue._alpha * 0.9 - 1,0);
}
else
{
_root.cue._visible = false;
}
if(this.phaseDelay > 0)
{
this.phaseDelay -= _global.dt;
return undefined;
}
switch(this.phase)
{
case 0:
this.snd.play("thunderRumble");
if(_root.missionAccomplished())
{
_root.levelsPlayed = _root.levelsPlayed + 1;
_root.actTimeBonus = _root.levelsPlayed * Math.floor(_root.timeLeft / 1000);
_root.totalScore += _root.actTimeBonus;
_root.actScore += _root.actTimeBonus;
_root.osd.gotoAndPlay("welldone");
}
else
{
_root.osd.gotoAndPlay("timeout");
}
this.phaseDelay = 30;
this.phase = this.phase + 1;
break;
case 1:
if(_root.missionAccomplished())
{
_root.tube.empty();
}
this.phaseDelay = 30;
this.phase = this.phase + 1;
break;
case 2:
if(_root.missionAccomplished())
{
var i = 0;
while(i < _root.ballsAmount)
{
_root.balls[i].mc.gotoAndPlay("vanish");
i++;
}
}
this.phaseDelay = 30;
this.phase = this.phase + 1;
break;
case 3:
this.phase = this.phase + 1;
if(_root.missionAccomplished())
{
this.loadLevel(_root.actLvl + 1);
}
break;
case 4:
this.snd.play("gameover");
_root.osd.gotoAndPlay("gameover");
this.phase = this.phase + 1;
break;
case "alreadydead":
this.phase = 5;
case 5:
}
};
replaySave = function(slot)
{
if(slot)
{
this.replayDataSlots[slot] = this.replayData;
var i = 0;
while(i < this.ballsAmount)
{
i++;
}
return undefined;
}
this.replayData = new Array();
var i = 0;
while(i < this.ballsAmount)
{
this.replayData[i] = {x:this.balls[i].x,y:this.balls[i].y,vx:this.balls[i].vx,vy:this.balls[i].vy};
i++;
}
};
replayLoad = function(slot)
{
if(slot)
{
this.replayData = this.replayDataSlots[slot];
}
if(!this.replayData)
{
return undefined;
}
var i = 0;
while(i < this.ballsAmount)
{
this.balls[i].setPos(this.replayData[i].x,this.replayData[i].y);
this.balls[i].setSpeed(this.replayData[i].vx,this.replayData[i].vy);
i++;
}
this.cue._visible = false;
this.cue._alpha = 0;
this.startRoll();
};
standardShot = function()
{
this.balls[0].vx = 20;
this.balls[0].vy = 0;
this.startRoll();
};
pot = function(value, id)
{
this.snd.play("pot");
_root.balls[id].spot = 1;
if(value !== 0)
{
this.shotPots += "" + value;
if(_root.lvl.needOrder.substr(this.actPottedOrder.length,1) eq value || (this.nominated == value || this.nominated == 0 && value > 1) || this.validPotMode)
{
if(_root.lvl.dontRespotColors && value > 1)
{
_root.balls[id].spot = 0;
}
if(this.validPotMode)
{
_root.osd.gotoAndPlay("excellent");
_root.snd.play("excellent");
}
this.validPotMode = 1;
this.score(value);
if(value == 1)
{
this.nominatedNext = 0;
this.actPottedRed = this.actPottedRed + 1;
}
else
{
this.nominatedNext = 1;
this.actPottedColor = this.actPottedColor + 1;
}
this.actPottedOrder += value;
_root.tube.addBall(value);
}
else
{
_root.foul(4,"- 4 seconds for potting wrong ball");
}
}
else
{
_root.foul(4,"- 4 seconds for potting white ball");
}
};
score = function(value)
{
_root.actBreak += value;
_root.actScore += value * Math.floor(_root.timeLeft / 1000);
_root.totalScore += value * Math.floor(_root.timeLeft / 1000);
};
collision = function(b0, b1)
{
if(b0.id == 0 || b1.id == 0)
{
var col = b0.id + b1.id;
this.firstHit = col;
this.firstHitLegal = 1;
}
};
foul = function(seconds, text)
{
_root.lightning.gotoAndPlay("double");
_root.actFoul = text;
_root.timeLeft -= seconds * 1000;
_root.osd.gotoAndPlay("foul");
_root.snd.play("foul");
};
spotBall = function(id, flags)
{
var tableCenterX = _root.table.x0 + (_root.table.x1 - _root.table.x0) / 2;
var tableCenterY = _root.table.y0 + (_root.table.y1 - _root.table.y0) / 2;
var difficulty = 0.5;
var posX;
var posY;
putX = _root.lvlProto[id].x;
putY = _root.lvlProto[id].y;
while(true)
{
if(id == 0)
{
putX = _root.lvlProto[id].x;
putY = tableCenterY + (_root.table.y1 - _root.table.y0 - _root.ballSize - 2) * (Math.random() - 0.5);
}
else if(id == 1)
{
r0 = Math.random();
r1 = Math.random() - 0.5;
if(flags && 1)
{
r0 = Math.max(r0,0.2);
r1 = Math.max(0.3,Math.abs(r1));
if(_root.balls[0].y < tableCenterY)
{
r1 *= -1;
}
}
putX = _root.lvlProto[id].x + 85 * r0;
putY = _root.lvlProto[id].y + 150 * r1 * r0;
}
var space = 999;
var i = 0;
while(i < _root.ballsAmount)
{
if(!(i == id || _root.balls[i].potted > -1))
{
space = Math.min(space,_global.v2d.math.p2pDistance(putX,putY,_root.balls[i].x,_root.balls[i].y));
}
i++;
}
if(space > _root.ballSize + 1)
{
_root.balls[id].reset();
_root.balls[id].setPos(putX,putY);
_root.balls[id].mc.gotoAndPlay("appear");
_root.balls[id].spot = 0;
break;
}
putX += _root.ballSize + 2;
if(putX > _root.table.x1 - _root.ballSize)
{
putX = _root.lvlProto[id].x;
putY += _root.ballSize + 2;
}
}
};
missionAccomplished = function()
{
if(_root.actPottedRed >= _root.lvl.needPottedRed && _root.actPottedColor >= _root.lvl.needPottedColor && _root.actBreak >= _root.lvl.needBreak && (_root.actBreak == _root.lvl.needExact || _root.lvl.needExact == 0) && (_root.actPottedOrder == _root.lvl.needOrder || _root.lvl.needOrder eq ""))
{
this.timer.running = false;
return true;
}
return false;
};
colorSwap = function()
{
if(!_root.lvl.colorSwap)
{
return undefined;
}
switch(_root.lvl.colorSwap)
{
case 1:
var i = 1;
while(i < _root.ballsAmount)
{
_root.balls[i].colorSwap();
i++;
}
break;
case 2:
var old = - 1;
var i = 0;
while(i < _root.ballsAmount)
{
if(_root.balls[i].glass)
{
old = i;
_root.balls[i].setGlass(0);
}
i++;
}
var closeId;
while(true)
{
closeId = random(_root.ballsAmount - 1) + 1;
if(closeId != old)
{
break;
}
}
_root.balls[closeId].setGlass(1);
break;
case 3:
var old = - 1;
var i = 0;
while(i < 6)
{
if(_root["l" + i].closed)
{
_root["l" + i].hand.gotoAndPlay("open");
}
else
{
old = i;
}
i++;
}
var closeId;
while(true)
{
closeId = random(6);
if(closeId != old)
{
break;
}
}
_root["l" + closeId].hand.gotoAndPlay("close");
}
};